<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Bottomnav;
use App\Http\Requests\BottomnavRequest;

class BottomnavController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $datas = Bottomnav::topnav()->with('subnavs')->get();
        return view('dashboard.bottomnav.index', ['datas' => $datas]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('dashboard.bottomnav.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(BottomnavRequest $request)
    {
        Bottomnav::create($request->all());
        return redirect()->route('admin.bottomnav.index');
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(Bottomnav $bottomnav)
    {
        return view('dashboard.bottomnav.create', ['data' => $bottomnav]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(BottomnavRequest $request, Bottomnav $bottomnav)
    {
        $bottomnav->update($request->all());
        return redirect()->route('admin.bottomnav.index');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy(Bottomnav $bottomnav)
    {
        $bottomnav->delete();
        return response()->json(['status' => 0]);
    }
}
